function concaturl(url) {
  return `${window.RPConfig.mgt}/dimension/${url}`;
}
function concaturl2(url) {
  return `${window.RPConfig.mgt}/dimensionDataUrl/${url}`;
}

export function getDimensionList({ responseProcess, param }) {
  $http.post(concaturl("list/page"), param).then(res => {
    // 状态为有效：禁用复选框，不可删除
    let { records } = res.data;
    records = this.$root.$options.filters["selection-disabled"](records);
    responseProcess(res.data);
  });
}
// 获取详情
export const getDimensionDetail = id => $http.post(concaturl("getById?id=" + id));

// 更新
export const updateDimension = param => $http.post(concaturl("update"), param);

// 添加
export const addDimension = param => $http.post(concaturl("add"), param);

// 删除
export const delDimension = param => $http.post(concaturl("deleteByIds"), param);

// 查询可用维度
export const queryAvailableDimensionList = param =>
  $http.post(concaturl("availableList?productId=" + param.productId + "&tenantCode=" + param.tenantCode));

// 数据源分页列表查询
export function getDimensionDataSourceList({ responseProcess, param }) {
  $http.post(concaturl2("list/page"), param).then(res => {
    // 状态为有效：禁用复选框，不可删除
    let { records } = res.data;
    records = this.$root.$options.filters["selection-disabled"](records);
    responseProcess(res.data);
  });
}

// 根据id删除
export const delDimensionDataSource = param => $http.post(concaturl2("deleteByIds"), param);

// 获取详情
export const getataSourceDetail = id => $http.post(concaturl2("getById?id=" + id));

// 更新
export const updateDataSource = param => $http.post(concaturl2("update"), param);

// 添加
export const addDataSource = param => $http.post(concaturl2("add"), param);

// 查询列表维度数据源分页列表接口
// export const queryListDimensionData = param => $http.post(concaturl2('list/providedData'), param);
export function queryListDimensionData({ responseProcess, param }) {
  // 添加默认参数
  $http.post(concaturl2("list/providedData"), param).then(res => {
    responseProcess(res.data);
  });
}

// 查询树型维度数据(包含数据源及已授权部分)
export const queryTreeDimensionData = param => $http.post(concaturl2("tree/allData"), param);

//  getApplicationByProductCode
export const getApplicationByProductCode = code =>
  $http.get(window.RPConfig.mgt.concat(`/application/getApplicationByProductCode?productCode=${code}`));

// 查询列表维度已授权数据分页列表接口
export const queryAssignedListDimensionData = param =>
  $http.post(`${window.RPConfig.mgt}/dimensionRoleDataRel/list/grantedData`, param);

// 维度数据角色授权
export const saveAssignedDimensionData = param =>
  $http.post(`${window.RPConfig.mgt}/dimensionRoleDataRel/authorize`, param);

//预览预览配置的数据源数据
  export const getDimenionData = param =>
  $http.post(concaturl2(`getDimensionData?dataStructType=${param.dataStructType}&dimensionDataUrl=${param.dimensionDataUrl}`), param);